<template>
  <div>
    <div style="width: 40%; margin: 20px;">
        <el-input placeholder="输入股东姓名" v-model="input">
        <el-button slot="append" icon="el-icon-search" @click="getAll"></el-button>
  </el-input></div>
  <div class="block" style="margin-left: -70%; margin: 20px 0px 20px -900px;">
    <span class="demonstration">加入日期：</span>
    <el-date-picker
      v-model="value"
      type="daterange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      value-format="yyyy-MM-dd">
    </el-date-picker>
    <el-button @click="getAll" type="primary">查询</el-button>
  </div>
  <div style="float: left;">
    <el-button @click="addHos" type="primary">添加股东</el-button>

  </div>

  <div style="float: left;width: 100%; background-color: #E4F2FF; border: 1px solid #6AB7FE; margin: 10px 0px; height: 40px; line-height: 40px;"><i class="el-icon-user-solid" style="color: #6AB7FE; line-height: 40px;"></i><label style="font-size: 14px;"> 股东总数：{{ pageInfo.total }}</label></div>
    <el-table
      ref="pageInfo.list"
      :data="pageInfo.list"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="realname" label="股东姓名" width="auto" > </el-table-column>
      <el-table-column prop="investment" label="投资金额" width="auto"> </el-table-column>
      <el-table-column prop="account" label="银行卡号" width="auto"></el-table-column>
      <el-table-column prop="profit" label="收益分成" width="auto">
        <template slot-scope="scope">
            {{ scope.row.profit}}<label>%</label>
            <el-button type="primary" icon="el-icon-edit" circle @click="openedit(scope.row)"></el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="account" label="医院地址" width="auto">
        <template slot-scope="scope">
            <label>{{ scope.row.province }}</label>
            <label>{{ scope.row.city }}</label>
            <label>{{ scope.row.district }}</label>
        </template>
      </el-table-column> -->
      <el-table-column prop="joinTime" label="加入时间" width="auto"></el-table-column>
      <el-table-column prop="address" label="操作" width="auto">
        <template slot-scope="scope">


            <el-popconfirm title="确定删除吗？" @confirm="delHos(scope.row.sid)">

                <el-button type="danger"  slot="reference" icon="el-icon-delete" circle></el-button>
            </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :total="pageInfo.pageSize" @current-change="search">
    </el-pagination>
    <!-- 添加模态框开始 -->
    <el-dialog title="添加股东" :visible.sync="addVisable">
      <el-form ref="form" :model="form" label-width="100px">
  <el-form-item label="手机号码">
    <el-input v-model="form.phone"></el-input>
  </el-form-item>


</el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addVisable=false">取 消</el-button>
        <el-button type="primary" @click="saveAddHos">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加模态框结束 -->
    <!-- 修改模态框开始 -->
    <el-dialog title="修改收益分成" :visible.sync="updVisable">
        <el-input v-model="edit.profit"></el-input>

      <div slot="footer" class="dialog-footer">
        <el-button @click="updVisable=false">取 消</el-button>
        <el-button type="primary" @click="saveEdit">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 修改模态框结束 -->
  </div>
</template>

<script>
import { getShare,refDel,addShare,updShare} from '../api/Shareholder';
export default {
    data(){
        return{
            pageInfo:{
            pageNum:1
             },
            input:"",
            value:[],
            form:{},
            addVisable:0,
            shouyi:"",
            updVisable:0,
            edit:{profit:""}
        }
    },methods:{
        saveEdit(){

            updShare(this.edit).then(res=>{
                if(res.data.code == 200){
                    this.updVisable = 0
                    this.$message.success('修改成功')
                    this.getAll()
                }
            })
        },
        openedit(row){
            this.updVisable = 1
            this.edit.sid = row.sid
            this.edit.profit = row.profit
        },
        saveAddHos(){
            addShare(this.form).then(res=>{
                if(res.data.code == 200){
                    this.addVisable = 0
                    this.$message.success('添加成功，初始密码为123456')
                }
            })
        },
        addHos(){
            this.form = {}
            this.addVisable = 1
        },
        delHos(row){
            refDel(row).then(res=>{
            if(res.data.code == 200){
                this.$message.success('删除成功')
                this.getAll()
            }else{
                this.$message.error('删除失败')
            }
        })
        },
        getAll(){
            getShare({pageNum:this.pageInfo.pageNum,value:this.input,dateArr:this.value}).then(res=>{
                this.pageInfo = res.data.data
            })
        }
    },
    mounted(){
        this.getAll()
    }
}
</script>

<style>

</style>
